import { createRouter, createWebHistory } from "vue-router"

const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	routes: [
		{
			path: "/",
			name: "home",
			component: () => import("../views/HomeView.vue"),
			meta: { title: "主页" },
		},
		{
			path: "/:pathMatch(.*)*",
			name: "NotFound",
			component: () => import("../views/NotFound.vue"),
			meta: { title: "404 未找到" },
		},
	],
})

router.beforeEach((to, from, next) => {
	document.title = (to.meta.title as string | undefined | null) ?? "Vue3 项目模板"
	next()
})

export default router
